clear all
close all
%load demog data
data=xlsread('..\FlowData\DemogUS.xlsx','demog');
data=data(:,2:end);

%load nber data
nber=xlsread('..\FlowData\DemogUS.xlsx','nber');
nber=[nber;zeros(4,1)];


% XXXXXXXXXXXX US XXXXXXXXXXXXXXXXXXX
%Using BLS data  back to 1960 (5 age groups)
LF=data(:,1:9);
Pop=data(:,10:18);
U=data(:,19:27);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define main qties of interest:

% Order is young, prime-age male, prime-age female, old

%Pop share
Omega=[Pop(:,1)./sum(Pop,2) (Pop(:,2)+Pop(:,4)+Pop(:,6))./sum(Pop,2) ...
    (Pop(:,3)+Pop(:,5)+Pop(:,7))./sum(Pop,2) (Pop(:,8)+Pop(:,9))./sum(Pop,2)];

%LF share
omega=[LF(:,1)./sum(LF,2) (LF(:,2)+LF(:,4)+LF(:,6))./sum(LF,2) ...
    (LF(:,3)+LF(:,5)+LF(:,7))./sum(LF,2) (LF(:,8)+LF(:,9))./sum(LF,2)];

%LFPR
lfp=omega./Omega.*kron(sum(LF,2)./sum(Pop,2), ones(1,4));

%UR
ur=[U(:,1)./LF(:,1) (U(:,2)+U(:,4)+U(:,6))./(LF(:,2)+LF(:,4)+LF(:,6)) ...
    (U(:,3)+U(:,5)+U(:,7))./(LF(:,3)+LF(:,5)+LF(:,7)) (U(:,8)+U(:,9))./(LF(:,8)+LF(:,9))];
ur_agg=sum(U,2)./sum(LF,2);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figure: Demog facts for US
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure, 
subplot(221), set(gca,'FontSize',8)
plot(100*omega(:,1),'k','LineWidth',2);
hold on, plot(100*omega(:,2),'LineWidth',2,'LineStyle','--','Color',[.5 .5 .5 ]);
plot(100*omega(:,3),'LineWidth',1,'Marker','o','MarkerSize',4,'Color',[.2 .2 .2]);
plot(100*omega(:,4),'LineWidth',1,'LineStyle','-','Color','k');
set(gca,'Xtick',1:20:length(omega)), xlim([1 length(omega)+1])
set(gca,'Xticklabel',num2str((1960:20:2015)'))
ylabel('ppt'), %ylim([-.8 .8])
title('Labor force share')

subplot(222), 
set(gca,'FontSize',8)
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(100*ur(:,1),'k','LineWidth',2);
hold on, plot(100*ur(:,2),'LineWidth',2,'LineStyle','--','Color',[.5 .5 .5 ]);
plot(100*ur(:,3),'LineWidth',1,'Marker','o','MarkerSize',4,'Color',[.2 .2 .2]);
plot(100*ur(:,4),'LineWidth',1,'LineStyle','-','Color','k');
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
% ylim(h2,[4.9 6.3])
ylabel('ppt')
set(gca,'Xtick',1:20:length(omega)), xlim([1 length(omega)+1])
set(gca,'Xticklabel',num2str((1960:20:2015)'))
set(h2,'XLim',get(h1,'XLim'),'Layer','top')
title('Unemployment rate')

subplot(223), 
set(gca,'FontSize',8)
plot(100*Omega(:,1),'k','LineWidth',2);
hold on, plot(100*Omega(:,2),'LineWidth',2,'LineStyle','--','Color',[.5 .5 .5 ]);
plot(100*Omega(:,3),'LineWidth',1,'Marker','o','MarkerSize',4,'Color',[.2 .2 .2]);
plot(100*Omega(:,4),'LineWidth',1,'LineStyle','-','Color','k');
set(gca,'Xtick',1:20:length(omega)), xlim([1 length(omega)+1])
set(gca,'Xticklabel',num2str((1960:20:2015)'))
ylabel('ppt','Fontsize',8), %ylim([-.8 .8])
set(gca,'FontSize',8)
title('Population share')

subplot(224), 
set(gca,'FontSize',8)
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(100*lfp(:,1),'k','LineWidth',2);
hold on, plot(100*lfp(:,2),'LineWidth',2,'LineStyle','--','Color',[.5 .5 .5 ]);
plot(100*lfp(:,3),'LineWidth',1,'Marker','o','MarkerSize',4,'Color',[.2 .2 .2]);
plot(100*lfp(:,4),'LineWidth',1,'LineStyle','-','Color','k');
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
% ylim(h2,[4.9 6.3])
ylabel('ppt')
set(gca,'Xtick',1:20:length(omega)), xlim([1 length(omega)+1])
set(gca,'Xticklabel',num2str((1960:20:2015)'))
set(h2,'XLim',get(h1,'XLim'),'Layer','top')
title('Labor force participation rate')
legend('16-24','Male 25-54','Female 25-54','55-85','Orientation','Horizontal','Fontsize',8)


